﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Shop_Manager.business
{
    class SalesBsn
    {
        public String GenerateBillingCode() {
            String billCode = "HDB";
            int count=0;
            DataConnect dtconn=new DataConnect();
            SqlConnection sqlconn = dtconn.connectDB();

            string today = DateTime.Now.Date.ToString("dd/MM/yyyy");

            SqlCommand command = new SqlCommand("getBillCountByDate", sqlconn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@date", SqlDbType.NVarChar).Value = today;

            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    count = reader.GetInt32(0);
                }
            }
            else
            {
                Console.WriteLine("No rows found.");
            }

            today = DateTime.Now.Date.Day.ToString() + "" + DateTime.Now.Date.Month.ToString() + "" + DateTime.Now.Date.Year.ToString();
            billCode = billCode + today + "-" + Convert.ToString(count+1);

            dtconn.closeConnect();
            return billCode;
        }
    }
}
